Skip to content

feat: implement env_nested_delimiter support for nested configuration#49

Merged
vilsonrodrigues merged 1 commit into
msgflux:mainfrom
FatJun:feat/env-nested-delimiter
Mar 22, 2026
Merged

feat: implement env_nested_delimiter support for nested configuration#49
vilsonrodrigues merged 1 commit into
msgflux:mainfrom
FatJun:feat/env-nested-delimiter

Conversation

@FatJun

@FatJun FatJun commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Summary

env_nested_delimiter was declared in SettingsConfigDict but never used. This implements the actual nested env var unfolding so that variables like DATABASE__HOST=localhost are resolved into nested struct fields.

Changes

  • Change env_nested_delimiter default from "__" to None (opt-in)
  • Add env_nested_max_depth config (0 = unlimited)
  • Add _resolve_field_type to convert BaseSettings types to struct equivalents (handles Union, Annotated, and generic types)
  • Add _collect_nested_env_values with delimiter-aware env scanning
  • Add 10 tests covering nesting, prefix, depth limit, dotenv, Optional

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvement
  • CI/CD improvement
  • Chore/maintenance

Testing

  • Tests pass locally (uv run pytest -v)
  • Added new tests for this change
  • Updated existing tests

Documentation

  • Updated README.md (if API changed)
  • Updated CHANGELOG.md (if notable change)
  • Added/updated code comments
  • Added/updated docstrings

Checklist

  • Code formatted (uv run ruff format)
  • Lint checks pass (uv run ruff check)
  • Tests pass (uv run pytest -v)
  • Version NOT changed (maintainers bump version after merge)
  • Commit messages follow conventional commits
  • No breaking changes (or documented above)
  • Added tests for new features
  • Documentation is up to date

Additional Notes

env_nested_delimiter was declared in SettingsConfigDict but never used.
This implements the actual nested env var unfolding so that variables
like DATABASE__HOST=localhost are resolved into nested struct fields.

- Change env_nested_delimiter default from "__" to None (opt-in)
- Add env_nested_max_depth config (0 = unlimited)
- Add _resolve_field_type to convert BaseSettings types to struct
  equivalents (handles Union, Annotated, and generic types)
- Add _collect_nested_env_values with delimiter-aware env scanning
- Add 10 tests covering nesting, prefix, depth limit, dotenv, Optional
@FatJun FatJun requested a review from vilsonrodrigues as a code owner March 22, 2026 19:39

@vilsonrodrigues vilsonrodrigues left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the contribution, great work implementing the nested delimiter support and adding thorough test coverage.

@vilsonrodrigues vilsonrodrigues left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FatJun approved

@vilsonrodrigues vilsonrodrigues merged commit c276075 into msgflux:main Mar 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants